#include <QtTest>

#include "test_SequenceItem.h"
#include "sequenceitem.h"
#include "QString"

const int exampleDelayMS = 1000;
const QString  exampleLabel("1. Track01");
const SequenceItem::eventType exampleType = SequenceItem::TRACK;
const SequenceItem::eventType invalidType = (SequenceItem::eventType)0xFF;
const int exampleNextIndex = 1;



test_SequenceItem::test_SequenceItem()
{
}

/**
 * @brief Show how to create the object
 */
void test_SequenceItem::testCreation()
{
   SequenceItem  *item = new SequenceItem( exampleDelayMS, exampleLabel, exampleType,
                                           exampleNextIndex, this);
   QVERIFY( item != NULL);

   QVERIFY( item->delayMs() == exampleDelayMS);
   QVERIFY( item->label() == exampleLabel);
   QVERIFY( item->type() == exampleType);
   QVERIFY( item->indexOfNext() == exampleNextIndex);

   delete item;
}

void test_SequenceItem::testComaprison()
{
   SequenceItem  *item1 = new SequenceItem( exampleDelayMS, exampleLabel, exampleType,
                                            exampleNextIndex, this);
   SequenceItem  *item2 = new SequenceItem( exampleDelayMS, exampleLabel, exampleType,
                                            exampleNextIndex, this);
   QVERIFY( *item1 == *item2);
}

/**
 * @brief example of constructor without parameters
 */
void test_SequenceItem::testDefaultValues()
{
   SequenceItem  *item = new SequenceItem();
   QVERIFY( item != NULL);

   QCOMPARE( item->delayMs(), 0);
   QCOMPARE( item->label(), QString());
   QCOMPARE( (int)(item->type()), (int)SequenceItem::INVALID_EVENT);

   delete item;
}

/**
 * @brief Show how data are stored in project file
 */
void test_SequenceItem::testSerializeTrack()
{
   SequenceItem  *item = new SequenceItem( exampleDelayMS, exampleLabel, SequenceItem::TRACK,
                                           SequenceItem::NEXT_IS_UNDEFINED, this);
   QString storageData;

   storageData = item->serialize();
   QCOMPARE( storageData, QString("TRACK  \"1. Track01\"  1000  -1"));

   delete item;
}

void test_SequenceItem::testSerializeStoppingEvent()
{
   SequenceItem  *item = new SequenceItem( SequenceItem::DELAY_INFINITE, exampleLabel,
                                           exampleType, SequenceItem::NEXT_IS_UNDEFINED, this);
   QString storageData;

   storageData = item->serialize();
   QCOMPARE( storageData, QString("TRACK  \"1. Track01\"  -1  -1"));

   delete item;
}

void test_SequenceItem::testSerializeLight()
{
   SequenceItem  *item = new SequenceItem( exampleDelayMS, QString("Ambient 1"), SequenceItem::LIGHT,
                                           SequenceItem::NEXT_IS_UNDEFINED, this);
   QString storageData;

   storageData = item->serialize();
   QCOMPARE( storageData, QString("LIGHT  \"Ambient 1\"  1000  -1"));

   delete item;
}

/**
 * @brief invalid value for event type parameter
 */
void test_SequenceItem::testSerializeWrongEvent()
{
   SequenceItem  *item = new SequenceItem( exampleDelayMS, exampleLabel, invalidType,
                                           SequenceItem::NEXT_IS_UNDEFINED, this);
   QString storageData;

   storageData = item->serialize();
   QVERIFY( storageData == QString());

   delete item;
}
